<?php

/* HTML.php
 *
 * (C) 2012, StaySimple CMS team.
 *
 * This file is part of StaySimple.
 * http://code.google.com/p/stay-simple-cms/
 *
 * StaySimple is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * StaySimple is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with StaySimple.  If not, see <http://www.gnu.org/licenses/>.
 */

abstract class HTML {

    public static function comboBox($name, $values = array(), $selected = null, $extra = array()) {

        $options = array();
        foreach ($values as $key => $title) {
            $options[] = ('<option value="' . $key . '"' . ($key == $selected ? ' selected="selected"' : '') . '>' . $title . '</option>');
        }

        $extras = array();
        if (!empty($extra) && is_array($extra)) {
            foreach ($extra as $property => $value) {
                $extras[] = $property . '="' . $value . '"';
            }
        }

        return '<select id="' . $name . '" name="' . $name . '"' . implode(' ', $extras) . '>' . implode('', $options) . '</select>';
    }

    public static function textField($name, $value, $extra = array()) {
        $extras = array();
        if (!empty($extra) && is_array($extra)) {
            foreach ($extra as $property => $pvalue) {
                $extras[] = $property . '="' . $pvalue . '"';
            }
        }

        return '<input type="text" id="' . $name . '" name="' . $name . '" value="' . $value . '" ' . implode(' ', $extras) . '/>';
    }

    public static function passwordField($name, $value, $extra = array()) {
        $extras = array();
        if (!empty($extra) && is_array($extra)) {
            foreach ($extra as $property => $pvalue) {
                $extras[] = $property . '="' . $pvalue . '"';
            }
        }

        return '<input type="password" id="' . $name . '" name="' . $name . '" value="' . $value . '" ' . implode(' ', $extras) . '/>';
    }

    public static function checkBox($name, $checked = false, $extra = array()) {
        $extras = array();
        if (!empty($extra) && is_array($extra)) {
            foreach ($extra as $property => $pvalue) {
                $extras[] = $property . '="' . $pvalue . '"';
            }
        }

        return '<input type="checkbox" id="' . $name . '" name="' . $name . '"' . implode(' ', $extras) . ($checked ? ' checked="checked"' : '') . ' />';
    }

}
